package com.lcsu.myThread;

import org.junit.Test;

public class MyThread1 {
    /**
     * 重写 Thread run方法
     */
    @Test
    public void mOverrideRun() {
        Thread thread = new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(1000);
                    System.out.println("threaf is  ruin---" + Thread.currentThread().getName());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 给 Thread 传入 Ruanable、的实现
     */
    @Test
    public void mThreadGetRunnable() {
        new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(1000);
                    System.out.println("threaf is  ruin---" + Thread.currentThread().getName());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Test
    public void mTimeTest() {
        new myTime().mTest();
    }

    @Test
    public void mSubTest() {
        final Bussiness bussiness = new Bussiness();
        //子线程
        new Thread(() -> {
            for (int i = 0; i < 3; i++) {
                bussiness.subMethod();
            }
        }).start();

        //主线程
        for (int i = 0; i < 3; i++) {
            bussiness.mainMethod();
        }
    }
}






